package com.junzerg.tooltip.controller;

import com.junzerg.tooltip.component.PoiComponent;
import com.junzerg.tooltip.service.IAmapService;
import com.junzerg.tooltip.service.IPoiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;

/**
 * @author pengjz <br>
 * @version 1.0 <br>
 * @description PoiController <br>
 * @date 2022/4/10 17:06 <br>
 */
@RestController
@Slf4j
@RequestMapping("/poi")
@Validated
public class PoiController extends BaseController {

    @Autowired
    private IAmapService amapService;

    @Autowired
    private PoiComponent poiComponent;

    @GetMapping("/text")
    public Object getPlaceByText(
            @RequestParam(value = "keywords", required = false) String keywords,
            @RequestParam(value = "types", required = false, defaultValue = "120000") String types,
            @RequestParam(value = "city", required = false, defaultValue = "100000") String city,
            @RequestParam(value = "citylimit", required = false, defaultValue = "false") Boolean citylimit,
            @RequestParam(value = "size", required = false, defaultValue = "20") Integer offset,
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer page
    ) {
        log.info("[getPlaceByText]keywords:{}, types:{}, city:{}, citylimit:{}, offset:{}, page:{}", keywords, types, city, citylimit, offset, page);
        amapService.getPlaceByTextFromAmap(keywords, types, city, citylimit, offset, page);
        return success();
    }

    @GetMapping("/amap")
    public Object getAmapPoi() {
        log.info("getAmpPoi");
        poiComponent.getAmapPoi();
        return success();
    }


}